package cn.edu.niit.server.service;

import java.io.File;
import java.io.FileInputStream;
import sun.misc.BASE64Encoder;

public class ImageTools {

    public static String imageToBase64Str(File imgFile) {
        byte[] data = null;
        try {
            FileInputStream inputStream = new FileInputStream(imgFile);
            data = new byte[inputStream.available()];
            inputStream.read(data);
            inputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(data);
    }
}
